<template>
  <div class="progress">
    <div class="progress-parent">
      <div v-if="type === 'dashboard'" class="dashboard-parent">
        <el-progress :percentage="percentage" :class="type === 'circle' ? 'circle' : 'dashboard'" :type="type" :color="color" :width="width" :format="formatProcessText" />
        <div class="centerText">
          <div v-if="iconName" class="progress-icon">
            <el-icon :name="iconName" />
          </div>
          <div class="progress-text" :class="!iconName ? 'noIcon' : ''" v-html="content" />
        </div>
        <div v-if="endText && startText" class="sub">
          <span class="start">{{ startText }}</span>
          <span class="end">{{ endText }}</span>
        </div>
        <span class="progress-tit">{{ $t(title) }}</span>
      </div>
      <div v-if="type === 'circle'" class="circle-parent">
        <el-progress :percentage="percentage" :class="type === 'circle' ? 'circle' : 'dashboard'" :type="type" :color="color" :width="width" :format="formatProcessText" />
        <div class="centerText">
          <div v-if="iconName" class="progress-icon">
            <el-icon :name="iconName" />
          </div>
          <div class="progress-text" :class="!iconName ? 'noIcon' : ''" v-html="content" />
        </div>
        <div v-if="endText && startText" class="sub">
          <span class="start">{{ startText }}</span>
          <span class="end">{{ endText }}</span>
        </div>
        <span class="progress-tit">{{ $t(title) }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import props from './mixin'

export default {
  name: 'CircleProgress',
  props: {
    ...props
  },
  computed: {
    content() {
      if (typeof this.format === 'function') {
        return this.format(this.percentage) || ''
      } else {
        return `${this.percentage}%`
      }
    }
  },
  methods: {
    formatProcessText() {
      return ''
    }
  }
}
</script>

<style scoped lang="scss">
/deep/.el-progress-circle{
  width: 100px!important;
  height: 100px!important;
}
.progress-parent,.progress{
  margin: 0 auto;
  position: relative;
  width: 100px!important;
  .centerText {
    border-radius: 50%;
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
  }
  .progress-icon{
    padding: 5px;
    background-color: #7262f6;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /deep/.progress-text{
    font-size: 13px;
    font-weight: bold;
    color: #020763;
    margin-top: 10px;
    color: #fff;
    span{
      font-size: 13px!important;
    }
    //position: absolute;
    //bottom: 35px;
    //transform: translateX(-50%);
    //left: 50%;
  }
  .progress-text.noIcon{
    font-size: 24px;
    font-weight: bold;
    color: #020763;
    //position: absolute;
    //bottom: 50%;
    //transform: translate(-50%,50%);
    //left: 50%;
  }
  .sub{
    overflow: hidden;
    margin: 0 auto;font-size: 12px;
    display: flex;
    justify-content: space-between;
    position: absolute;
    width: 100%;
    bottom: 14px;
    span{
      color: #fff;
      font-size: 12px;
      white-space: nowrap;
    }
  }
  .progress-tit{
    color: #fff;
    font-size: 13px;
    margin: 5px 0;
    display: block;
    white-space: nowrap;
  }
  /deep/ .dashboard .el-progress-circle__track {
    stroke: #f6bd78;
  }
  /deep/.circle .el-progress-circle__track {
    stroke: #f6bd78;
  }
}
</style>
